import 'package:flutter/material.dart';

class AlignLayoutRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Align Layout'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          TopRight(),
          Divider(),
          RightOverflow(),
          Divider(),
          Fractional(),
          Divider(),
          CenterLayout(),
        ],
      ),
    );
  }
}

class TopRight extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      // height: 120,
      // width: 120,
      color: Colors.blue[50],
      child: Align(
        widthFactor: 2,
        heightFactor: 2,
        alignment: Alignment.topRight,
        child: FlutterLogo(
          size: 60,
        ),
      ),
    );
  }
}

class RightOverflow extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.blue[50],
      child: Align(
        widthFactor: 2,
        heightFactor: 2,
        alignment: Alignment(2, 0),
        child: FlutterLogo(
          size: 60,
        ),
      ),
    );
  }
}

// 实际偏移 = (FractionalOffse.x * childWidth, FractionalOffse.y * childHeight)
class Fractional extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 120,
      height: 120,
      color: Colors.blue[50],
      child: Align(
        alignment: FractionalOffset(0.2, 0.6),
        child: FlutterLogo(
          size: 60,
        ),
      ),
    );
  }
}

class CenterLayout extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        DecoratedBox(
          decoration: BoxDecoration(color: Colors.red),
          child: Center(
            child: Text('xxx'),
          ),
        ),
        DecoratedBox(
          decoration: BoxDecoration(color: Colors.red),
          child: Center(
            widthFactor: 1.2,
            heightFactor: 1.2,
            child: Text('xxx'),
          ),
        ),
      ],
    );
  }
}
